//
//  ICMAppointmentOtherInfoModel.m
//  ICrEAM
//
//  Created by rainimute on 16/11/11.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMAppointmentOtherInfoModel.h"
#import "ICMAppointmentBasicInfoView.h"

@implementation ICMAppointmentOtherInfoModel

- (void)setupAppointmentOtherInfoModelWithBasicInfoView:(ICMAppointmentBasicInfoView *)basicInfoView{
    self.CONTACTOR_NAME = basicInfoView.customerNameView.contentText;
    self.CONTACTOR_MOBILE = basicInfoView.customerPhoneNumberView.contentText;
    self.BOOKING_BUSINESS_TYPE = ICMEnumIntToString(ICMEnumBookingBusinessTypeDefault);//预约业务类型
    
    self.BOOKING_REPAIR_TYPE = @"";
    NSString *repair_type_string = basicInfoView.appointmentSubTypeView.contentText?basicInfoView.appointmentSubTypeView.contentText:@"";
    if (![repair_type_string isEqualToString:@""]) {
        NSArray *repair_type_strings = [repair_type_string componentsSeparatedByString:@","];
        NSMutableArray *type_codes = [NSMutableArray array];
        for (NSString *type in repair_type_strings) {
            NSString *code = [ICrEAMTool getRepiarTypeCodeWithRepiarName:type];
            if (code) {
                [type_codes PACA_AddObject:code];
            }
        }
        self.BOOKING_REPAIR_TYPE = [type_codes componentsJoinedByString:@";"];//预约业务子类型 @"CGBY;YIWX"
    }
    
    self.BOOKING_COME_TIME = basicInfoView.stepInTimeView.contentText;
    self.LABOUR_POSITION_CODE = basicInfoView.stationCode;
    self.EST_REPAIR_TIME = basicInfoView.EST_REPAIR_TIME;
    self.DRIVE_ADD = basicInfoView.pickUpAddressView.contentText;
    self.REMARK = basicInfoView.tipsView.contentText;
    self.RECEPTION_TIME = basicInfoView.RECEPTION_TIME;
    self.EST_STATION_TIME = basicInfoView.EST_STATION_TIME;
    self.TIME_SEQ = @"";
    if ([self.EST_REPAIR_TIME floatValue]>0 && !IsStrEmpty(self.EST_STATION_TIME)) {
        NSMutableArray *seq = [NSMutableArray array];
        NSInteger startCount = [self hourAndMinTextGetCount:[self.EST_STATION_TIME componentsSeparatedByString:@" "].lastObject];
        NSInteger count = [self.EST_REPAIR_TIME floatValue]/0.25;
        for (NSInteger i=0; i<count; i++) {
            [seq PACA_AddObject:[@(startCount+i) stringValue]];
        }
        self.TIME_SEQ = [seq componentsJoinedByString:@","];
    }
}

- (NSInteger)hourAndMinTextGetCount:(NSString *)hourAndMin{
    NSString *currentHour = [[hourAndMin componentsSeparatedByString:@":"]firstObject];
    NSString *currentMin = [[hourAndMin componentsSeparatedByString:@":"]lastObject];
    NSInteger currentCount = ([currentHour integerValue]-7)*4;
    currentCount += [currentMin integerValue]/15+1;
    if ([currentMin integerValue]%15 == 0) {
        currentCount --;
    }
    return currentCount;
}


@end
